home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / gamesmaster / source / asm / sprites / sprites.s < prev   
Encoding:
Text File  |  1996-09-08  |  4.9 KB  |  156 lines

  1. ;Sprite example
  2. ;--------------
  3. ;This example shows you how to set up a 16 colour OCS sprite with a doubled
  4. ;X axis (32 pixels width).  Those with hardware experience will know that it
  5. ;takes 4 sprite banks to do this successfully in OCS, which leaves you with
  6. ;another 4 banks to do with what you will.
  7. ;
  8. ;Notice that the screen is only 1 bitplane large, even though the sprite is
  9. ;16 colours.  This is because the sprite is independent of the screen
  10. ;bitmap.  You can access colours not in the screen by setting up a large
  11. ;palette and specifying the amount of colours in SS_AmtColours (in this
  12. ;case, we set 32 colours to access the sprite colour bank).
  13. ;
  14. ;Try moving the sprite around a bit with the mouse.  The LMB exits the demo.
  15.  
  16.     opt    o+
  17.  
  18.     INCLUDE    "exec/exec_lib.i"
  19.     INCLUDE    "games/games_lib.i"
  20.     INCLUDE    "games/games.i"
  21.  
  22. CALL    MACRO
  23.     jsr    _LVO\1(a6)
  24.     ENDM
  25.  
  26.     SECTION    "Sprites",CODE
  27.  
  28. ;===========================================================================;
  29. ;                             INITIALISE DEMO
  30. ;===========================================================================;
  31.  
  32. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  33.     move.l    ($4).w,a6
  34.     lea    GMS_Name(pc),a1
  35.     moveq    #$00,d0
  36.     CALL    OpenLibrary
  37.     move.l    d0,GMS_Base
  38.     beq.s    Error
  39.  
  40.     move.l    GMS_Base(pc),a6          ;Run this demo at a user-selected
  41.     CALL    SetUserPri               ;priority.
  42.  
  43.     lea    ScreenStruct(pc),a0      ;Initialise our screen for use.
  44.     CALL    Add_Screen
  45.     tst.l    d0
  46.     bne.s    Error
  47.  
  48.     CALL    Show_Screen              ;Show our screen.
  49.  
  50.     lea    SparkieStruct(pc),a1
  51.     CALL    Init_Sprite
  52.     CALL    Update_Sprite            ;First get him onto the screen.
  53.  
  54.     moveq    #JPORT1,d0               ;Read from port 1
  55.     CALL    Read_Mouse               ;Initialise the port.
  56.  
  57. ;===========================================================================;
  58. ;                                MAIN LOOP
  59. ;===========================================================================;
  60.  
  61. Loop:    addq.w    #1,d7                    ;Animation/Frame delay, so that
  62.     btst    #0,d7                    ; our anim does not run too fast!
  63.     beq.s    .Mouse
  64.     cmp.w    #5,SPR_Frame(a1)         ;Do the animation for the sprite.
  65.     beq.s    .reset                   ;(simply by increasing the frame
  66.     addq.w    #1,SPR_Frame(a1)         ; number).
  67.     bra.s    .Mouse
  68. .reset    clr.w    SPR_Frame(a1)
  69.  
  70. .Mouse    moveq    #JPORT1,d0               ;Read from port 1
  71.     CALL    Read_Mouse               ;Go get mouse position.
  72.     move.w    d0,d1
  73.     asr.w    #8,d0
  74.     add.w    d0,SPR_XPos(a1)
  75.     ext.w    d1
  76.     add.w    d1,SPR_YPos(a1)
  77.  
  78.     CALL    Wait_OSVBL               ;Allow screen-switching.
  79.     CALL    Update_Sprite            ;Put Sparkie on the screen.
  80.  
  81.     btst    #MB_LMB,d0
  82.     beq.s    Loop
  83.  
  84. ;===========================================================================;
  85. ;                              RETURN TO DOS
  86. ;===========================================================================;
  87.  
  88. ReturnToDOS:
  89.     move.l    GMS_Base(pc),a6
  90.     lea    ScreenStruct(pc),a0
  91.     CALL    Delete_Screen            ;Give back screen memory etc.
  92. Error:    move.l    GMS_Base(pc),a1
  93.     move.l    ($4).w,a6
  94.     CALL    CloseLibrary
  95. Quit:    MOVEM.L    (SP)+,A0-A6/D1-D7
  96.     moveq    #$00,d0
  97.     rts
  98.  
  99. ;===========================================================================;
  100. ;                                  DATA
  101. ;===========================================================================;
  102.  
  103. GMS_Name:
  104.     dc.b    "games.library",0
  105.     even
  106. GMS_Base:
  107.     dc.l    0
  108.  
  109. SparkieStruct:
  110.     dc.l    "SPV1",0          ;Structure version.
  111.     dc.w    0                 ;Number 0.
  112.     dc.l    Gfx_Sparkie       ;Ptr to graphic.
  113.     dc.w    100,100           ;Beginning X/Y position
  114.     dc.w    0                 ;Current frame.
  115.     dc.w    16,21             ;Width, Height.
  116.     dc.w    16                ;Amt of colours.
  117.     dc.w    16                ;Colour start in palette.
  118.     dc.w    2                 ;Amt of planes.
  119.     dc.w    LORES|XLONG       ;Attributes.
  120.     dc.w    0                 ;PlayField position.
  121.     dc.l    0,0               ;Private.
  122.  
  123. AMT_PLANES =    1
  124.  
  125. ScreenStruct:
  126.     dc.l    "GSV1",0
  127.     dc.l    0,0,0             ;Screen_Mem1/2/3
  128.     dc.l    0                 ;Screen link.
  129.     dc.l    ScreenPalette     ;Address of the screen palette.
  130.     dc.l    0                 ;Address of a ColourList.
  131.     dc.l    32                ;Amt of colours in the palette.
  132.     dc.w    320,256,320,256   ;Screen & Pic Height/Width
  133.     dc.w    AMT_PLANES        ;Amt_Planes
  134.     dc.w    0,0               ;X/Y Top Of Screen
  135.     dc.w    0,0               ;X/Y Pic Offsets (for scrolling).
  136.     dc.l    SPRITES|NOSPRBDR  ;Special attributes.
  137.     dc.w    LORES             ;Screen mode.
  138.     dc.b    INTERLEAVED       ;Screen type
  139.     dc.b    0                 ;Reserved.
  140.     even
  141.  
  142. ScreenPalette:
  143.     dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
  144.     dc.w    $0000,$0688,$0466,$0344,$0CC0,$0980,$0870,$0650
  145.     dc.w    $01C2,$0050,$0B0B,$0606,$0F20,$0910,$0BBB,$0FFF
  146.     dc.w    $00BF,$0068,$0568,$09BF,$0FF0,$0EE0,$0BA0,$0540
  147.  
  148. ;===========================================================================;
  149. ;                         ALL CHIP RAM DATA HERE
  150. ;===========================================================================;
  151.  
  152.     SECTION    "Graphics",DATA_C
  153.  
  154. Gfx_Sparkie:
  155.     INCBIN    "GAMESLIB:data/Sparkie.raw"
  156.